;(function ($) {
    /* 维修 平台分配 */
    var apiUrl = $("#apiUrl").val();
    $.repairPop = function (localDeviceId, localRepairId) {
        var modal = $('<div style="display: none;"></div>');
        if (localDeviceId) {
            modal.attr('id', 'assign-model');
            modal.html(
                '<div class="score-797987978">' +
                    '<div class="box-body">' +
                        '<div class="col-md-8">' +
                            '<table class="table table-striped table-bordered" border="0">' +
                                '<tr>' +
                                    '<td class="text-muted text-right">设备名称</td>' +
                                    '<td class="text-muted text-left"><span id="deviceNameSpan"></span></td>' +
                                    '<td class="text-muted text-right">设备型号</td>' +
                                    '<td class="text-muted text-left"><span id="deviceModelSpan"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted text-right">设备序列号</td>' +
                                    '<td class="text-muted text-left"><span id="snSpan"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted text-right">厂商</td>' +
                                    '<td class="text-muted text-left"><span id="manufacturerNameSpan"></span></td>' +
                                    '<td class="text-muted text-right">厂商联系人</td>' +
                                    '<td class="text-muted text-left"><span id="manufacturerContactsSpan"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted text-right">厂商联系人电话</td>' +
                                    '<td class="text-muted text-left"><span id="manufacturerPhoneSpan"></span></td>' +
                                    '<td class="text-muted text-right"> 维保合同有效期</td>' +
                                    '<td class="text-muted text-left"><span id="endGuaranteeDateSpan"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted text-right">设备保内外状态</td>' +
                                    '<td class="text-muted text-left"><span id="InsideOutsideStrSpan"></span></td>' +
                                    '<td class="text-muted text-right"> 维修商</td>' +
                                    '<td class="text-muted text-left"><span id="maintainerNameSpan"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted text-right">维修商联系人</td>' +
                                    '<td class="text-muted text-left"><span id="maintainerContactsSpan"></span></td>' +
                                    '<td class="text-muted text-right"> 维修商联系人电话</td>' +
                                    '<td class="text-muted text-left"><span id="maintainerPhoneSpan"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted text-right">医院联系人</td>' +
                                    '<td class="text-muted text-left"><span id="hospitalContactsSpan"></span></td>' +
                                    '<td class="text-muted text-right"> 医院联系电话</td>' +
                                    '<td class="text-muted text-left"><span id="hospitalPhoneSpan"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted " colspan="4">医院填写信息</td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted " style="text-align: right">医院选择的服务商是</td>' +
                                    '<td class="text-muted " style="text-align: left"><span id="serviceCompanySpan"></span></td>' +
                                    '<td class="text-muted " style="text-align: right">服务商联系人</td>' +
                                    '<td class="text-muted " style="text-align: left"><span id="serviceNameSpan"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted " style="text-align: right">服务商联系电话</td>' +
                                    '<td class="text-muted " style="text-align: left" colspan="3"><span id="servicePhoneSpan"></span></td>' +
                                '</tr>' +
                                '<tr id="engineerTr"></tr>' +
                                '<tr id="examineTr"></tr>' +
                            '</table>' +
                            '<form id="assignForm" class="form-horizontal col-md-12" style="padding: 15px">' +
                                '<div id="assignServiceDiv" class="col-md-12">' +
                                    '<h5><b class="text-aqua" style="margin-left:20px">服务商信息</b></h5>' +
                                    '<div class="col-md-6 form-group">' +
                                        '<label  class="col-sm-4 control-label text-muted">服务商类型<span class="text-red">*</span></label>' +
                                        '<div class="col-md-8" >' +
                                            '<div class="radio">' +
                                                '<label>' +
                                                    '<input type="radio" class="flat-green" name="serviceType" value="1102">厂商' +
                                                '</label>' +
                                                '<label>' +
                                                    '<input type="radio" class="flat-green" name="serviceType" value="1105">经销商' +
                                                '</label>' +
                                                '<label>' +
                                                    '<input type="radio" class="flat-green" name="serviceType" value="1103">维修商' +
                                                '</label>' +
                                            '</div>' +
                                        '</div>' +
                                    '</div>' +
                                    '<input type="hidden" name="serviceId">' +
                                    '<div class="col-md-6 form-group" id="assignManufacturerDiv" >' +
                                        '<label  class="col-sm-4 control-label text-muted">厂商</label>' +
                                        '<div class="col-md-8" >' +
                                            '<input type="text" class="form-control" name="manufacturerName" readonly>' +
                                            '<input type="hidden" name="manufacturerId">' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="col-md-6 form-group" id="assignSupplierDiv" style="display: none;">' +
                                        '<label  class="col-sm-4 control-label text-muted">经销商</label>' +
                                        '<div class="col-md-8" >' +
                                            '<input type="text" class="form-control" name="supplierName" readonly>' +
                                            '<input type="hidden" name="supplierId">' +
                                        '</div>' +
                                    '</div>' +
                                    '<div id="assignMaintainerDiv" style="display: none;">' +
                                        '<div class="col-md-6 form-group" >' +
                                            '<label  class="col-sm-4 control-label text-muted">维修商</label>' +
                                            '<div class="col-md-8" >' +
                                                '<input type="text" class="form-control" name="serviceName" data-provide="typeahead"' +
                                                       'autocomplete="off">' +
                                            '</div>' +
                                        '</div>' +
                                        '<div class="col-md-6 form-group" >' +
                                            '<label  class="col-sm-4 control-label text-muted">维修商联系人</label>' +
                                            '<div class="col-md-8" >' +
                                                '<input type="text" class="form-control" name="serviceContacts">' +
                                            '</div>' +
                                        '</div>' +
                                        '<div class="col-md-6 form-group" >' +
                                            '<label  class="col-sm-4 control-label text-muted">联系人电话</label>' +
                                            '<div class="col-md-8" >' +
                                                '<input type="text" class="form-control" name="servicePhone">' +
                                            '</div>' +
                                        '</div>' +
                                    '</div>' +
                                '</div>' +
                                '<div id="engineerDiv" class="col-md-12">' +
                                    '<h5><b class="text-aqua" style="margin-left:20px">工程师信息</b></h5>' +
                                    '<div class="col-md-12 form-group" style="height: 34px">' +
                                        '<label  class="col-sm-4 control-label text-muted">是否指派负责人</label>' +
                                        '<div class="col-md-8" >' +
                                            '<div class="radio" style="margin-top: 3px">' +
                                                '<label>' +
                                                    '<input type="radio" class="flat-green" value="1" name="is_dispatch">是' +
                                                '</label>' +
                                                '<label>' +
                                                    '<input type="radio" class="flat-green" name="is_dispatch" value="0">否' +
                                                '</label>' +
                                            '</div>' +
                                        '</div>' +
                                    '</div>' +
                                    '<div id="dispatchDiv" style="display: none;">' +
                                        '<div class="col-md-12  form-group">' +
                                            '<label  class="col-sm-4 control-label text-muted">负责人姓名<span class="text-red">*</span></label>' +
                                            '<div class="col-md-8" >' +
                                                '<input type="text" class="form-control" name="engineerName" id="engineerName">' +
                                            '</div>' +
                                        '</div>' +
                                        '<div class="col-md-12  form-group">' +
                                            '<label  class="col-sm-4 control-label text-muted">负责人电话<span class="text-red">*</span></label>' +
                                            '<div class="col-md-8" >' +
                                                '<input type="text" class="form-control" name="engineerPhone" id="engineerPhone">' +
                                            '</div>' +
                                        '</div>' +
                                    '</div>' +
                                '</div>' +
                            '</form>' +
                        '</div>' +
                        '<div class="col-md-4">' +
                            '<div class="col-md-12">' +
                                '<div class="col-md-12">' +
                                    '<label  class="col-sm-12 control-label text-muted">故障照片</label>' +
                                '</div>' +
                                '<div class="col-md-12" style="display: flex;justify-content: flex-start;flex-wrap: wrap" id="img_box_one">' +
                                '</div>' +
                            '</div>' +
                        '</div>' +
                    '</div>' +
                    '<div class="box-footer">' +
                        '<span class="pull-right">' +
                            '<button data-iziModal-close class="btn btn-default" style="margin-right: 5px">关闭</button>' +
                            '<button id="submit-btn" class="btn btn-primary" style="margin-right: 5px">提交</button>' +
                        '</span>' +
                    '</div>' +
                '</div>'
            );
            $('body').append(
                '<!--审核模态框-->' +
                '<div id="examine-maintainer" style="display: none;">' +
                    '<div class="box-body">' +
                        '<form id="examine-maintainer-form" class="form-horizontal" method="post">' +
                            '<input type="hidden" name="repairId">' +
                            '<input type="hidden" name="serviceType" value="1103">' +
                            '<div class="col-md-12">' +
                                '<label  class="col-sm-4 control-label text-muted">服务商名称</label>' +
                                '<div class="col-md-8 form-group" >' +
                                    '<input type="text" class="form-control" name="serviceName" readonly>' +
                                '</div>' +
                            '</div>' +
                            '<div class="col-md-12">' +
                                '<label  class="col-sm-4 control-label text-muted">服务商联系人</label>' +
                                '<div class="col-md-8 form-group" >' +
                                    '<input type="text" class="form-control" name="serviceContacts">' +
                                '</div>' +
                            '</div>' +
                            '<div class="col-md-12">' +
                                '<label  class="col-sm-4 control-label text-muted">服务商联系电话</label>' +
                                '<div class="col-md-8 form-group" >' +
                                    '<input type="text" class="form-control" name="servicePhone">' +
                                '</div>' +
                            '</div>' +
                            '<div class="col-md-12">' +
                                '<label  class="col-sm-4 control-label text-muted">审核</label>' +
                                '<div class="col-md-8 form-group" >' +
                                    '<div class="radio">' +
                                        '<label>' +
                                            '<input type="radio" class="flat-green" name="examine" value="1" checked>通过' +
                                        '</label>' +
                                        '<label>' +
                                            '<input type="radio" class="flat-green" name="examine" value="0" >不通过' +
                                        '</label>' +
                                    '</div>' +
                                '</div>' +
                            '</div>' +
                            '<div class="col-md-12">' +
                                '<label  class="col-sm-4 control-label text-muted">审核说明</label>' +
                                '<div class="col-md-8 form-group" >' +
                                    '<input type="text" class="form-control" name="examineComment">' +
                                '</div>' +
                            '</div>' +
                        '</form>' +
                        '<div class="box-footer">' +
                            '<span class="pull-right">' +
                                '<button data-iziModal-close class="btn btn-default" style="margin-right: 5px">关闭</button>' +
                            '</span>' +
                            '<span class="pull-right">' +
                                '<button  class="btn btn-info" id="saveExamineMaintainer" style="margin-right: 5px">提交</button>' +
                            '</span>' +
                        '</div>' +
                    '</div>' +
                '</div>'
            );
        } else {
            modal.attr('id', 'assign_model_Two');
            modal.html(
                '<div class="score-797987978">' +
                    '<div class="box-body">' +
                        '<div class="col-md-8">' +
                            '<table class="table table-striped table-bordered" border="0">' +
                                '<tr>' +
                                    '<td class="text-muted text-right">医院</td>' +
                                    '<td class="text-muted text-left"><span id="hospitalName"></span></td>' +
                                    '<td class="text-muted text-right">地址</td>' +
                                    '<td class="text-muted text-left"><span id="address"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted text-right">备注</td>' +
                                    '<td class="text-muted text-left"><span id="remark"></span></td>' +
                                    '<td class="text-muted text-right">联系人</td>' +
                                    '<td class="text-muted text-left"><span id="linkman"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted text-right">手机号码</td>' +
                                    '<td class="text-muted text-left"><span id="phoneNumber"></span></td>' +
                                    '<td class="text-muted text-right"> 故障时间</td>' +
                                    '<td class="text-muted text-left"><span id="malfunctionTime"></span></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted " style="text-align: right">品牌</td>' +
                                    '<td class="text-muted " style="text-align: left"><span id="brand"></span></td>' +
                                    '<td class="text-muted " style="text-align: right">是否指派负责人</td>' +
                                    '<td class="text-muted " style="text-align: left"><label>' +
                                        '<input type="radio" class="flat-green" value="1" name="is_dispatch">是' +
                                    '</label>' +
                                        '<label>' +
                                            '<input type="radio" checked class="flat-green" name="is_dispatch" value="0">否' +
                                        '</label></td>' +
                                '</tr>' +
                                '<tr id="dispatch_Div" style="display: none;">' +
                                    '<td class="text-muted text-right">负责人姓名<span class="text-red">*</span></td>' +
                                    '<td class="text-muted text-left"><input type="text" class="form-control" name="engineerName" id="engineerName_two"></td>' +
                                    '<td class="text-muted text-right"> 负责人电话<span class="text-red">*</span></td>' +
                                    '<td class="text-muted text-left"><input type="text" class="form-control" name="engineerPhone" id="engineerPhone_two"></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td class="text-muted " style="text-align: right">请选择</td>' +
                                    '<td class="text-muted " style="text-align: left">' +
                                        '<label>' +
                                            '<input type="radio" checked class="flat-green" name="serviceType" value="1102">厂商' +
                                        '</label>' +
                                        '<label>' +
                                            '<input type="radio" class="flat-green" name="serviceType" value="1103">维修商' +
                                        '</label>' +
                                    '</td>' +
                                    '<td class="text-muted " style="text-align: right"></td>' +
                                    '<td class="text-muted " style="text-align: left"></td>' +
                                '</tr>' +
                                '<tr class="box_one">' +
                                    '<td class="text-muted text-right">厂商<span class="text-red">*</span></td>' +
                                    '<td class="text-muted text-left">' +
                                        '<select name="Manufacturer_select" id="Manufacturer_select" style="width: 100%">' +
                                        '</select>' +
                                    '</td>' +
                                    '<td class="text-muted text-right"> 厂家联系人<span class="text-red">*</span></td>' +
                                    '<td class="text-muted text-left"><span id="Manufacturer_Linkman"></span></td>' +
                                '</tr>' +
                                '<tr class="box_one">' +
                                    '<td class="text-muted text-right">联系人电话<span class="text-red">*</span></td>' +
                                    '<td class="text-muted text-left">' +
                                        '<span id="Manufacturer_Phone"></span>' +
                                    '</td>' +
                                    '<td class="text-muted text-right"> 账号</td>' +
                                    '<td class="text-muted text-left"><span id="userName"></span></td>' +
                                '</tr>' +
                                '<tr class="box_one">' +
                                    '<td class="text-muted text-right">密码</td>' +
                                    '<td class="text-muted text-left">' +
                                        '<span id="password"></span>' +
                                    '</td>' +
                                    '<td class="text-muted text-right"></td>' +
                                    '<td class="text-muted text-left"></td>' +
                                '</tr>' +
                                '<tr class="box_two" style="display: none">' +
                                    '<td class="text-muted text-right">维修商<span class="text-red">*</span></td>' +
                                    '<td class="text-muted text-left">' +
                                        '<select name="Maintainer_select" id="Maintainer_select" style="width: 100%">' +
                                        '</select>' +
                                    '</td>' +
                                    '<td class="text-muted text-right"> 维修商联系人<span class="text-red">*</span></td>' +
                                    '<td class="text-muted text-left"><span id="Maintainer_Linkman"></span></td>' +
                                '</tr>' +
                                '<tr class="box_two" style="display: none">' +
                                    '<td class="text-muted text-right">联系人电话<span class="text-red">*</span></td>' +
                                    '<td class="text-muted text-left">' +
                                        '<span id="Maintainer_Phone"></span>' +
                                    '</td>' +
                                    '<td class="text-muted text-right"> 账号</td>' +
                                    '<td class="text-muted text-left"><span id="userName"></span></td>' +
                                '</tr>' +
                                '<tr class="box_two" style="display: none">' +
                                    '<td class="text-muted text-right">密码</td>' +
                                    '<td class="text-muted text-left">' +
                                        '<span id="password"></span>' +
                                    '</td>' +
                                    '<td class="text-muted text-right"></td>' +
                                    '<td class="text-muted text-left"></td>' +
                                '</tr>' +
                            '</table>' +
                        '</div>' +
                        '<div class="col-md-4">' +
                            '<div class="col-md-12">' +
                                '<div class="col-md-12">' +
                                    '<label  class="col-sm-12 control-label text-muted">设备照片</label>' +
                                '</div>' +
                                '<div class="col-md-12" style="display: flex;justify-content: flex-start;flex-wrap: wrap" id="box_img_one">' +
                                '</div>' +
                            '</div>' +
                            '<div class="col-md-12">' +
                                '<div class="col-md-12">' +
                                    '<label  class="col-sm-12 control-label text-muted">设备铭牌</label>' +
                                '</div>' +
                                '<div class="col-md-12" style="display: flex;justify-content: flex-start;flex-wrap: wrap" id="box_img_two">' +
                                '</div>' +
                            '</div>' +
                        '</div>' +
                    '</div>' +
                    '<div style="height: 400px"></div>' +
                    '<div class="box-footer">' +
                        '<span class="pull-right">' +
                            '<button data-iziModal-close class="btn btn-default" style="margin-right: 5px">关闭</button>' +
                            '<button  id="submit-btn" class="btn btn-primary" style="margin-right: 5px">提交</button>' +
                        '</span>' +
                    '</div>' +
                '</div>'
            );
        }
        $('body').append(modal);
        if (localDeviceId) {
            // 分配服务商Model
            modal.iziModal({
                title: "服务商",
                headerColor: '#00c0ef',
                rtl: false,
                width: 1300,
                zindex: 1042,
                focusInput: false,
                group: '',
                loop: false,
                history: false,
                overlayClose: false,
                autoOpen: false, // Boolean, Number
                bodyOverflow: true,
                closeOnEscape:false,
                onOpening: function () {
                    $("#assign-maintainer").val(null);
                    $("#assign-maintainer").select2({
                        language: 'zh-CN',
                        placeholder: '服务商',
                        allowClear: true
                    });
                    validator();
                    if(localDeviceId){
                        getDeviceInfo(localDeviceId);
                    }
                    $("input[name='is_dispatch'][value='0']").iCheck('check');
                },
                onOpened: function () {
                    $("#assignForm input[name='serviceType']").on("ifChecked",function (){
                        var value = $(this).val();
                        globalServiceType = value;
                        $("#assignMaintainerDiv input").val("");
                        if(value == 1103){
                            $("#assignMaintainerDiv").show();
                            $("#assignSupplierDiv").hide();
                            $("#assignManufacturerDiv").hide();
                            $("#assignServiceDiv").find("[name='serviceId']").val(null);
                            $("#assignForm input[value='0']").parents("label").hide();//如果是维修商必须选择指派工程师
                            $("#assignForm input[value='1']").iCheck("check");
                            localIsDispaxth = 1;
                            $("#dispatchDiv").show();
                            localIsDispaxth = 1;
                        }else if(value == 1102){
                            $("#assignManufacturerDiv").show();
                            $("#assignMaintainerDiv").hide();
                            $("#assignSupplierDiv").hide();
                            var manufacturerId = $("#assignMaintainerDiv").find("[name='manufacturerId']").val();
                            $("#assignServiceDiv").find("[name='serviceId']").val(manufacturerId);
                            $("#assignForm input[value='0']").parents("label").show();
                        }else if(value == 1105){
                            $("#assignManufacturerDiv").hide();
                            $("#assignMaintainerDiv").hide();
                            $("#assignSupplierDiv").show();
                            var supplierId = $("#assignSupplierDiv").find("[name='supplierId']").val();
                            $("#assignServiceDiv").find("[name='serviceId']").val(supplierId);
                            $("#assignForm input[value='0']").parents("label").show();
                        }else{
                            $("#assignManufacturerDiv").hide();
                            $("#assignMaintainerDiv").hide();
                            $("#assignSupplierDiv").hide();
                            $("#assignServiceDiv").find("[name='serviceId']").val(null);
                        }
                    }   );

                    $("[name='is_dispatch']").on("ifChecked",function (){
                        var value = $(this).val();
                        localIsDispaxth = value;
                        if(value == 1){
                            $("#dispatchDiv").show();
                            engineerNameV = hospitalContactsV = dispathTimeV = notEmptyValid;
                            engineerPhoneV = {
                                validators: {
                                    regexp: {
                                        regexp: /^1[3|4|5|7|8][0-9]\d{8}$/,
                                        message: '请填写正确的手机号码'
                                    }
                                }
                            }

                            hospitalPhoneV = {
                                validators: {
                                    notEmpty: {
                                        message: '不能为空'
                                    },
                                    regexp: {
                                        regexp: /^1[3|4|5|7|8][0-9]\d{8}$/,
                                        message: '请填写正确的手机号码'
                                    }
                                }
                            }
                        }else{
                            $("#dispatchDiv").hide();
                            engineerNameV = null;
                            hospitalContactsV = null;
                            dispathTimeV = null;
                            engineerPhoneV = null;
                            hospitalPhoneV = null;
                        }
                    });
                },
                onClosing: function () {},
                onClosed: function () {
                    modal.remove();
                }
            });
        } else {
            modal.iziModal({
                title: "维修处理",
                headerColor: '#00c0ef',
                rtl: false,
                width: 1300,
                height:600,
                zindex: 1042,
                focusInput: false,
                group: '',
                loop: false,
                history: false,
                overlayClose: false,
                autoOpen: false, // Boolean, Number
                bodyOverflow: true,
                // openFullscreen:true,
                closeOnEscape:false,
                onOpening: function () {
                    modal.find('select').select2({language: 'zh-CN', placeholder: '请选择'});
                    get_ManufacturerList();
                    get_MaintainerList();
                },
                onOpened: function () {
                    modal.find("[name='serviceType']").on("ifChecked",function (){
                        var value = $(this).val();
                        if(value == 1102){
                            $(".box_one").show();
                            $(".box_two").hide();
                        }else{
                            $(".box_two").show();
                            $(".box_one").hide();
                        }
                    });
                    modal.find("[name='is_dispatch']").on("ifChecked",function (){
                        var value = $(this).val();
                        if(value == 1){
                            $("#dispatch_Div").show();
                        }else{
                            $("#dispatch_Div").hide();
                        }
                    });
                    modal.find("#Manufacturer_select").on('change',function () {
                        var id  = $(this).val();
                        var obj = Manufacturer_select.filter(function (key,item) {
                            return id == key.manufacturerId
                        });
                        $('.box_one').find('#Manufacturer_Linkman').text(obj[0].manufacturerContacts);
                        $('.box_one').find('#Manufacturer_Phone').text(obj[0].manufacturerPhone);
                        $('.box_one').find('#userName').text(obj[0].userName);
                        if(obj[0].userName == null){
                            $('.box_one').find('#password').text(obj[0].password);
                        }else {
                            $('.box_one').find('#password').text(123456);
                        }
                    });
                    modal.find("#Maintainer_select").on('change',function () {
                        var id  = $(this).val();
                        var obj = Maintainer_select.filter(function (key,item) {
                            return id == key.maintainerId
                        });
                        $('.box_two').find('#Maintainer_Linkman').text(obj[0].maintainerContacts);
                        $('.box_two').find('#Maintainer_Phone').text(obj[0].maintainerPhone);
                        $('.box_two').find('#userName').text(obj[0].userName);

                        if(obj[0].userName == null){
                            $('.box_two').find('#password').text(obj[0].password);
                        }else {
                            $('.box_two').find('#password').text(123456);
                        }
                    })
                },
                onClosing: function () {},
                onClosed: function () {
                    modal.remove();
                }
            });
        }


        /*=====================================================================*/
        $('input.flat-green').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass: 'iradio_flat-green'
        });

        /* 提交绑定 */
        $('#submit-btn').click(function () {
            if (localDeviceId) {
                submitAssign();
            } else {
                save_info();
            }
        });

        /* 提交 */
        modal.find('.cancel, .iziModal-button-close').off().click(function (){
            messageObjArr[messageObjArr.index].isDoNow = true;
            dealPushMessage();
        });
        modal.find('.cancel').off().click(function (){
            modal.iziModal('close');
        });


        var globalServiceType,
            localIsDispaxth = 0;
        //获取设备信息
        function getDeviceInfo(id){
            publicAjax(apiUrl+"base/queryManufacturerByDeviceId","POST",{deviceId: id},function (data) {
                if(data.ret == 200){
                    $("#deviceNameSpan").html(data.data.deviceName || '');
                    $("#deviceModelSpan").html(data.data.deviceModel || '');
                    $("#snSpan").html(data.data.sn || '');
                    $("#lastUpkeepDateSpan").html(data.data.lastUpkeepDate || '');
                    $("#manufacturerNameSpan").html(data.data.manufacturerName || '');
                    $("#manufacturerContactsSpan").html(data.data.manufacturerContacts || '');//厂商联系人
                    $("#manufacturerPhoneSpan").html(data.data.manufacturerPhone || '');
                    $("#InsideOutsideStrSpan").html(data.data.guaranteeStatus || '');
                    $("#maintainerNameSpan").html(data.data.maintainerName ||'');
                    $("#maintainerContactsSpan").html(data.data.maintainerContacts ||'');
                    $("#maintainerPhoneSpan").html(data.data.maintainerPhone ||'');
                    $("#endGuaranteeDateSpan").html(data.data.endDate);
                    $("#hospitalContactsSpan").html(data.data.hospitalContacts ||'');
                    $("#hospitalPhoneSpan").html(data.data.hospitalPhone);
                    if(data.data.manufacturerId){
                        getAssignMaintainer(data.data.manufacturerId);
                    }
                }
            })
        }
        //获取分配时的维修商
        function getAssignMaintainer(mId){
            publicAjax(apiUrl+"base/queryMinListByMamuId","POST",{manufacturerId: mId},function (data) {
                if(data.ret == 200){
                    var html = "<option value=''></option>";
                    $.each(data.data,function (index,item) {
                        var isSelected = "";
                        if(item.manufacturer){
                            isSelected = "selected";
                        }
                        html += "<option value='"+item.maintainerId+"' "+isSelected+">"+item.maintainerName+"</option>";
                    });
                    $("#assign-maintainer").html(html);
                }else{
                    flavrShowByTime(data.msg,null,"danger",false);
                }
            });
        }

        var isCheckMaintainer = false, //是否需要审核维修商
            serviceName,
            serviceContacts,
            servicePhone;
        function getBaseInfo(){
            publicAjax(apiUrl + "repair/queryInfoPage","POST",{deviceId: localDeviceId, repairId: localRepairId},function (data){
                if(data.ret == 200){
                    if(data.data){
                        if(data.data.manufacturer != null){
                            $("#assignManufacturerDiv").find("[name='manufacturerName']").val(data.data.manufacturer.manufacturerName);
                            $("#assignManufacturerDiv").find("[name='manufacturerId']").val(data.data.manufacturer.manufacturerId);
                        }else{//如果没有厂商则不能选择厂商
                            $("#assignForm input[value='1102']").parents("label").hide();
                        }
                        if(data.data.supplier != null){
                            $("#assignSupplierDiv").find("[name='supplierName']").val(data.data.supplier.supplierName);
                            $("#assignSupplierDiv").find("[name='supplierId']").val(data.data.supplier.supplierId);
                        }else{//如果没有经销商则不能选择
                            $("#assignForm input[value='1105']").parents("label").hide();
                        }
                        $("#assignServiceDiv").find("[name='serviceType'][value='"+data.data.serviceType+"']").iCheck("check");
                        if(data.data.serviceType == 1103){//维修商
                            /*$("#assignMaintainerDiv").show();
                            $("#assignSupplierDiv").hide();
                            $("#assignManufacturerDiv").hide();*/
                            $("#assignServiceDiv").hide();
                            $("#assignForm input[value='0']").parents("label").hide();//如果是维修商必须选择指派工程师
                            $("#assignForm input[value='1']").iCheck("check");
                            localIsDispaxth = 1;
                            $("#dispatchDiv").show();
                            globalServiceType = data.data.serviceType;
                        }else if(data.data.serviceType == 1102){//厂商
                            /*$("#assignManufacturerDiv").show();
                            $("#assignMaintainerDiv").hide();
                            $("#assignSupplierDiv").hide();*/
                            $("#assignServiceDiv").hide();
                            $("#assignForm").find("[name='serviceId']").val(data.data.manufacturer.manufacturerId);
                            $("#assignForm input[name='0']").show();
                            $("#assignForm input[name='0']").iCheck("check");
                            $("#dispatchDiv").hide();
                            globalServiceType = data.data.serviceType;
                        }else if(data.data.serviceType == 1105){//经销商
                            /*$("#assignManufacturerDiv").hide();
                            $("#assignMaintainerDiv").hide();
                            $("#assignSupplierDiv").show();*/
                            $("#assignServiceDiv").hide();
                            $("#assignForm").find("[name='serviceId']").val(data.data.supplier.supplierId);
                            $("#assignForm input[value='0']").parents("label").show();
                            $("#assignForm input[value='0']").iCheck("check");
                            $("#dispatchDiv").hide();
                            globalServiceType = data.data.serviceType;
                        }else{
                            $("#assignServiceDiv").show();
                            $("#assignManufacturerDiv").hide();
                            $("#assignMaintainerDiv").show();
                            $("#assignSupplierDiv").hide();
                            $("#assignServiceDiv [name='serviceType'][value='1103']").iCheck("check");
                            // globalServiceType = 1103;
                            $("#assignForm input[value='0']").parents("label").hide();//如果没有选择服务商，则默认是维修商
                            $("#assignForm input[value='1']").iCheck("check");
                            localIsDispaxth = 1;
                            $("#dispatchDiv").show();
                        }
                        serviceName = data.data.serviceName || '';
                        serviceContacts = data.data.serviceContacts || '';
                        servicePhone = data.data.servicePhone || '';
                        $("#assignForm input[name='serviceName']").val(serviceName);
                        $("#assignForm input[name='serviceContacts']").val(serviceContacts);
                        $("#assignForm input[name='servicePhone']").val(servicePhone);
                        switch (globalServiceType){
                            case 1102:
                                //厂商
                                $("#serviceCompanySpan").html("厂商: "+data.data.manufacturer.manufacturerName || "");
                                $("#serviceNameSpan").html(data.data.manufacturer.manufacturerContacts || "");
                                $("#servicePhoneSpan").html(data.data.manufacturer.manufacturerPhone || "");
                                break;
                            case 1105:
                                //经销商
                                $("#serviceCompanySpan").html("经销商: "+data.data.supplier.supplierName);
                                $("#serviceNameSpan").html(data.data.supplier.supplierContacts || "");
                                $("#servicePhoneSpan").html(data.data.supplier.supplierPhone || "");
                                break;
                            case 1103:
                                //维修商
                                $("#serviceCompanySpan").html("维修商: "+serviceName);
                                $("#serviceNameSpan").html(serviceName);
                                $("#servicePhoneSpan").html(servicePhone);
                                //医院端选择的维修商需要审核。。。这里是添加审核按钮
                                if(data.data.examine == null && data.data.serviceType==1103){
                                    isCheckMaintainer = true;//
                                    var buttonHtml = "<button type='button' id='shenhe-2321312' class='btn btn-info btn-sm' data-toggle='tooltip'>审核</button>";
                                    $("#serviceCompanySpan").append("&nbsp;&nbsp;").append(buttonHtml);
                                    $('#shenhe-2321312').click(function () {
                                        bindServiceInfo(localRepairId, serviceName, serviceContacts, servicePhone);
                                    });
                                }
                                break;
                            default :
                                //无
                                $("#serviceCompanySpan").html("医院没有选择服务商");
                                $("#serviceNameSpan").html(serviceName);
                                $("#servicePhoneSpan").html(servicePhone);
                        }
                        $("#examineTr").html("");
                        var examine = data.data.examine;
                        var examineComment = data.data.examineComment || '';
                        if(examine != null ){
                            var html = "";
                            if(examine == 1){
                                html = "<td class='text-muted' style='text-align: right'>审核结果：</td><td class='text-muted' style='text-align: left'>通过</td>"+
                                    "<td class='text-muted' style='text-align: right'>审核说明：</td><td class='text-muted' style='text-align: left'>"+examineComment+"</td>";
                                $("[name='is_dispatch'][value='1']").iCheck("check");
                                $("#dispatchDiv").show();
                            }else if(examine == 0){
                                html = "<td class='text-muted' style='text-align: right'>审核结果：</td><td class='text-muted' style='text-align: left'>不通过</td>"+
                                    "<td class='text-muted' style='text-align: right'>审核说明：</td><td class='text-muted' style='text-align: left'>"+examineComment+"</td>";
                                $("#assignServiceDiv").show();
                            }
                            $("#examineTr").html(html);
                        }
                        //如果有工程师或工程师联系方式，则默认选择指派工程师
                        if(data.data.engineerName || data.data.engineerPhone){
                            $("#assignForm input[value='1']").iCheck("check");
                            localIsDispaxth = 1;
                            $("#engineerName").val(data.data.engineerName || '');
                            $("#engineerPhone").val(data.data.engineerPhone || '');
                            $("#dispatchDiv").show();
                        }


                        var imgList = data.data.fileList;
                        var imgStr = '';

                        if(imgList.length > 0){
                            $.each(imgList,function (key,val) {
                                imgStr += '<img src="'+val.fileUrl+'" style="width: 20%; background-color:#ccc; height: 100px; margin: 2px">';
                            });
                        }else {
                            imgStr = '<p style="margin-left: 20px">暂无数据</p>';
                        }

                        $('#assign-model #img_box_one').html(imgStr);
                        $('#assign-model #img_box_one').find("img").viewer({inline: false});
                    }
                }else{
                    flavrShowByTime(data.msg,null,"danger",false);
                }
            });
        }

        //分配提交
        var isAssign = false;
        function submitAssign(){
            if(!isCheckMaintainer){
                $('#assignForm').bootstrapValidator('validate');
                if($('#assignForm').data('bootstrapValidator').isValid()){
                    if(!isAssign){
                        isAssign = true;
                        if(globalServiceType == 1103){//维修商没有seviceId
                            $("#assignServiceDiv").find("[name='serviceId']").val(null);
                            serviceId = null;
                            serviceName = $("#assignForm input[name='serviceName']").val();
                            servicePhone = $("#assignForm input[name='servicePhone']").val();
                            serviceContacts = $("#assignForm input[name='serviceContacts']").val();
                            localIsDispaxth = 1;
                        }else if(globalServiceType == 1105){//厂商和经销商没有维修商信息
                            serviceId = $("#assignSupplierDiv input[name='supplierId']").val();
                            serviceName = $("#assignSupplierDiv input[name='supplierName']").val();
                            servicePhone = null;
                            serviceContacts = null;
                        }else if(globalServiceType == 1102){
                            serviceId = $("#assignManufacturerDiv input[name='manufacturerId']").val();
                            serviceName = $("#assignManufacturerDiv input[name='manufacturerName']").val();
                            servicePhone = null;
                            serviceContacts = null;
                        }else{
                            serviceId = null;
                        }
                        var submitData = {
                            repairId: localRepairId,
                            serviceId: $("#assignServiceDiv").find("[name='serviceId']").val(),
                            isDispatch: localIsDispaxth,
                            serviceId: serviceId,
                            serviceName: serviceName,
                            serviceType: globalServiceType || $("#assignForm input[name='serviceType']:checked").val(),
                            servicePhone: servicePhone,
                            serviceContacts: serviceContacts,
                            /*dispatchTime: localIsDispaxth == 1 ? $("#dispathTime").val(): null,*/
                            hospitalContacts: localIsDispaxth == 1 ? $("#hospitalContacts").val() : null,
                            hospitalPhone: localIsDispaxth == 1 ? $("#hospitalPhone").val() : null,
                            engineerName: localIsDispaxth == 1 ? $("#engineerName").val() : null,//负责人
                            engineerPhone: localIsDispaxth == 1 ? $("#engineerPhone").val() : null//负责人电话
                        }
                        publicAjax(apiUrl+"repair/distribution","POST",submitData,function (data) {
                            if(data.ret == 200){
                                flavrShowByTime("操作成功",null,"success",null);
                                modal.iziModal("close");
                                messageObjArr[messageObjArr.index].isDoNow = true;
                                dealPushMessage();
                            }else{
                                flavrShowByTime(data.msg,null,"danger",null);
                            }
                            isAssign = false;
                        })
                    }
                }
            }else{
                flavrShowByTime("请先审核维修商",null,"danger",null);
            }
        }

        /*======================================================================================================*/
        /* 审核 */
        function bindServiceInfo(upkeepId,serviceName,serviceContacts,servicePhone){
            $("#examine-maintainer-form").find("[name='serviceName']").val(serviceName);
            $("#examine-maintainer-form").find("[name='serviceContacts']").val(serviceContacts);
            $("#examine-maintainer-form").find("[name='servicePhone']").val(servicePhone);
            $("#examine-maintainer-form").find("[name='repairId']").val(localRepairId);
            $("#examine-maintainer").iziModal("open",this);
        }
        // 审核维修商
        $("#examine-maintainer").iziModal({
            title: "审核维修商",
            headerColor: '#00c0ef',
            rtl: false,
            width: 800,
            zindex: 1044,
            focusInput: false,
            group: '',
            loop: false,
            history: false,
            overlayClose: false,
            autoOpen: false, // Boolean, Number
            bodyOverflow: true,
            onOpening: function () {
                $("input[name='examine']").iCheck({
                    checkboxClass: 'icheckbox_flat-green',
                    radioClass: 'iradio_flat-green'
                });
                $("#examine-maintainer-form input[value='1']").iCheck("check");
            },
            onOpened: function () {},
            onClosing: function () {
                $('#examine-maintainer-form')[0].reset();
            },
            onClosed: function () {

            }
        });
        $("#saveExamineMaintainer").click(function (){
            saveExamineMaintainer();
        });
        function saveExamineMaintainer(){
            isCheckMaintainer = false;
            $("#serviceCompanySpan button").remove();
            if($("#examine-maintainer-form input[name='examine']:checked").val() == 1){//审核通过
                publicAjax(apiUrl+"repair/agree","POST",$("#examine-maintainer-form"),function (data) {
                    if(data.ret ==200){
                        $("#examine-maintainer").iziModal("close",this);
                        getBaseInfo();
                    }else{
                        flavrShowByTime(data.msg,null,"danger",false);
                    }
                })
            }else{//审核不通过,重新选择服务商
                publicAjax(apiUrl+"repair/disagree","POST",{repairId: localRepairId, examineComment: $("#examine-maintainer-form input[name='examineComment']").val()},function (data) {
                    if(data.ret ==200){
                        $("#assignForm input[value='1102']").parents("label").show();
                        $("#assignForm input[value='1103']").parents("label").show();
                        $("#assignForm input[value='1105']").parents("label").show();
                        $("#examine-maintainer").iziModal("close",this);
                        getBaseInfo();
                    }else{
                        flavrShowByTime(data.msg,null,"danger",false);
                    }
                })

            }
        }
        /* 审核模态框结束================================================================================================== */

        //保存维修处理信息
        function save_info() {
            var data = {};
            data.repairId = localRepairId;
            data.isDispatch = $("input[name='is_dispatch']:checked").val();
            if($('#assign_model_Two').find("input[name='is_dispatch']:checked").val() == 1){
                data.engineerName = $('#assign_model_Two').find('#engineerName_two').val();
                data.engineerPhone = $('#assign_model_Two').find('#engineerPhone_two').val();
                if(data.engineerName == '' || data.engineerPhone == ''){
                    flavrShowByTime('请注意负责人姓名跟电话填写正常',null,'danger',false);
                    return
                }
            }

            data.serviceType = $('#assign_model_Two').find("input[name='serviceType']:checked").val();


            if($('#assign_model_Two').find("input[name='serviceType']:checked").val() == 1102){

                data.serviceId = $('#assign_model_Two').find("#Manufacturer_select").val();
                data.serviceName = $('#assign_model_Two').find("#Manufacturer_select").find('option:selected').text();
                data.serviceContacts = $('#assign_model_Two').find("#Manufacturer_Linkman").text();
                data.servicePhone = $('#assign_model_Two').find("#Manufacturer_Phone").text();
                if(data.serviceId == ''){
                    flavrShowByTime('请选择厂商',null,'danger',false);
                    return
                }

            }
            if($('#assign_model_Two').find("input[name='serviceType']:checked").val() == 1103){

                data.serviceId = $('#assign_model_Two').find("#Maintainer_select").val();
                data.serviceName = $('#assign_model_Two').find("#Maintainer_select").find('option:selected').text();
                data.serviceContacts = $('#assign_model_Two').find("#Maintainer_Linkman").text();
                data.servicePhone = $('#assign_model_Two').find("#Maintainer_Phone").text();
                if(data.serviceId == ''){
                    flavrShowByTime('请选择维修商',null,'danger',false);
                    return
                }

            }
            publicAjax(apiUrl + "repair/distribution","POST",data,function (data){
                if(data.ret == 200){
                    flavrShowByTime('操作成功',null,"success",false);
                    $("#assign_model_Two").iziModal("close",this);
                    modal.iziModal("close");
                    messageObjArr[messageObjArr.index].isDoNow = true;
                    dealPushMessage();
                }else{
                    flavrShowByTime(data.msg,null,"danger",false);
                }
            });
        }

        /*=========无设备报修开始====================================================================================*/
        //获取维修处理信息
        function get_info() {
            publicAjax(apiUrl + "repair/details","POST",{repairId:localRepairId},function (data){
                if(data.ret == 200){
                    var obj = data.data;
                    $('#assign_model_Two').find("#hospitalName").text(obj.hospitalName);
                    $('#assign_model_Two').find("#address").text(obj.address);
                    $('#assign_model_Two').find("#remark").text(obj.remark);
                    $('#assign_model_Two').find("#linkman").text(obj.repairPerson);
                    $('#assign_model_Two').find("#phoneNumber").text(obj.repairPersonPhone);
                    $('#assign_model_Two').find("#malfunctionTime").text(obj.faultTime);
                    $('#assign_model_Two').find("#brand").text(obj.brand);
                    var list1 = obj.fileList;
                    var str1 = '';
                    var str2 = '';
                    $.each(list1,function (key,val) {
                        if(val.fileTypeName == '设备图片'){
                            str1 += '<img src="'+val.fileUrl+'" alt="" style="width: 20%; background-color:#ccc; height: 100px; margin: 2px">';
                        }else {
                            str2 += '<img src="'+val.fileUrl+'" alt="" style="width: 20%; background-color:#ccc; height: 100px; margin: 2px">';
                        }
                    })
                    if(str1 == ''){
                        str1 = '<p style="margin-left: 20px">暂无数据</p>'
                    }
                    if(str2 == ''){
                        str2 = '<p style="margin-left: 20px">暂无数据</p>'
                    }
                    $('#box_img_one').html(str1);
                    $('#box_img_two').html(str2);
                    $('#box_img_one').find("img").viewer();
                    $('#box_img_two').find("img").viewer();
                }else{
                    flavrShowByTime(data.msg,null,"danger",false);
                }
            });
        }

        //获取厂商
        function get_ManufacturerList() {
            publicAjax(apiUrl + "base/queryManufacturer","POST",{},function (data){
                if(data.ret == 200){
                    var list = data.data;
                    Manufacturer_select = list;
                    var str = '<option value=""></option>';
                    $.each(list,function (key,val) {
                        str += '<option value="'+val.manufacturerId+'">'+val.manufacturerName+'</option>'
                    });
                    $('#assign_model_Two').find('#Manufacturer_select').html(str);
                }else{
                    flavrShowByTime(data.msg,null,"danger",false);
                }
            });
        }

        //获取维修商
        function get_MaintainerList() {
            publicAjax(apiUrl + "base/queryMaintainer","POST",{},function (data){
                if(data.ret == 200){
                    var list = data.data;
                    Maintainer_select = data.data;
                    var str = '<option value=""></option>';
                    $.each(list,function (key,val) {
                        str += '<option value="'+val.maintainerId+'">'+val.maintainerName+'</option>'
                    });
                    $('#assign_model_Two').find('#Maintainer_select').html(str);
                }else{
                    flavrShowByTime(data.msg,null,"danger",false);
                }
            });
        }
        /*=========无设备报修结束====================================================================================*/

        //分配表单校验
        var engineerNameV, engineerPhoneV, hospitalContactsV, hospitalPhoneV, dispathTimeV;
        var notEmptyValid = {
            validators: {
                notEmpty: {
                    message: '不能为空'
                }
            }
        };
        engineerPhoneV = {
            validators: {
                regexp: {
                    regexp: /^1[3|4|5|7|8][0-9]\d{8}$/,
                    message: '请填写正确的手机号码'
                }
            }
        };
        hospitalPhoneV = {
            validators: {
                notEmpty: {
                    message: '不能为空'
                },
                regexp: {
                    regexp: /^1[3|4|5|7|8][0-9]\d{8}$/,
                    message: '请填写正确的手机号码'
                }
            }
        };
        var assignMaintainerV = engineerNameV = hospitalContactsV = notEmptyValid;
        function validator(){
            $('#assignForm').bootstrapValidator({
                excluded: [':disabled', ':hidden', ':not(:visible)'],
                live: 'enabled',
                message: '非有效值',
                fields: {
                    assignMaintainer: assignMaintainerV,
                    engineerName: engineerNameV,
                    hospitalContacts: hospitalContactsV,
                    engineerPhone: engineerPhoneV,
                    hospitalPhone: hospitalPhoneV
                }
            });
        }

        /* 打开模态框 */
        modal.iziModal('open');
        if (localDeviceId) {
            getBaseInfo();
        } else {
            get_info();
        }
    };
})(jQuery);